home *** CD-ROM | disk | FTP | other *** search
/ Creating Your Own America Online Web Pages / Creating Your Own America Online Web Pages.iso / TOOLS / TEX2RTF / SOURCES.ZIP / SRC / WXWIN / WX_HASH.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-21  |  3.5 KB  |  112 lines

  1. /*
  2.  * File:     wx_hash.h
  3.  * Purpose:  Basic hash table implementation
  4.  *
  5.  *                       wxWindows 1.50
  6.  * Copyright (c) 1993 Artificial Intelligence Applications Institute,
  7.  *                   The University of Edinburgh
  8.  *
  9.  *                     Author: Julian Smart
  10.  *                       Date: 7-9-93
  11.  *
  12.  * Permission to use, copy, modify, and distribute this software and its
  13.  * documentation for any purpose is hereby granted without fee, provided
  14.  * that the above copyright notice, author statement and this permission
  15.  * notice appear in all copies of this software and related documentation.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS,
  18.  * IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
  19.  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  20.  *
  21.  * IN NO EVENT SHALL THE ARTIFICIAL INTELLIGENCE APPLICATIONS INSTITUTE OR THE
  22.  * UNIVERSITY OF EDINBURGH BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR
  23.  * CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM
  24.  * LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF
  25.  * DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
  26.  * THE USE OR PERFORMANCE OF THIS SOFTWARE.
  27.  */
  28.  
  29. #ifndef wxb_hashh
  30. #define wxb_hashh
  31.  
  32. #include "wx_obj.h"
  33. #include "wx_list.h"
  34.  
  35. /*
  36.  * A hash table is an array of user-definable size with lists
  37.  * of data items hanging off the array positions.  Usually there'll
  38.  * be a hit, so no search is required; otherwise we'll have to run down
  39.  * the list to find the desired item.
  40. */
  41.  
  42. #ifdef IN_CPROTO
  43. typedef       void    *wxHashTable ;
  44. #else
  45.  
  46. class wxHashTable: public wxObject
  47. {
  48.  public:
  49.   int n;
  50.   int current_position;
  51.   wxNode *current_node;
  52.  
  53.   unsigned int key_type;
  54.   wxList **hash_table;
  55.  
  56.   wxHashTable(unsigned int the_key_type, int size = 1000);
  57.   ~wxHashTable(void);
  58.  
  59.   // Note that there are 2 forms of Put, Get.
  60.   // With a key and a value, the *value* will be checked
  61.   // when a collision is detected. Otherwise, if there are
  62.   // 2 items with a different value but the same key,
  63.   // we'll retrieve the WRONG ONE. So where possible,
  64.   // supply the required value along with the key.
  65.   // In fact, the value-only versions make a key, and still store
  66.   // the value. The use of an explicit key might be required
  67.   // e.g. when combining several values into one key.
  68.   // When doing that, it's highly likely we'll get a collision,
  69.   // e.g. 1 + 2 = 3, 2 + 1 = 3.
  70.  
  71.   // key and value are NOT necessarily the same
  72.   void Put(long key, long value, wxObject *object);
  73.   void Put(long key, char *value, wxObject *object);
  74.  
  75.   // key and value are the same
  76.   void Put(long value, wxObject *object);
  77.   void Put(char *value, wxObject *object);
  78.  
  79.   // key and value not the same
  80.   wxObject *Get(long key, long value);
  81.   wxObject *Get(long key, char *value);
  82.  
  83.   // key and value are the same
  84.   wxObject *Get(long value);
  85.   wxObject *Get(char *value);
  86.  
  87.   // Deletes entry and returns data if found
  88.   wxObject *Delete(long key);
  89.   wxObject *Delete(char *key);
  90.  
  91.   wxObject *Delete(long key, int value);
  92.   wxObject *Delete(long key, char *value);
  93.  
  94.   // Construct your own integer key from a string, e.g. in case
  95.   // you need to combine it with something
  96.   long MakeKey(char *string);
  97.  
  98.   // Way of iterating through whole hash table (e.g. to delete everything)
  99.   // Not necessary, of course, if you're only storing pointers to
  100.   // objects maintained separately
  101.  
  102.   void BeginFind(void);
  103.   wxNode *Next(void);
  104.  
  105.   void DeleteContents(Bool flag);
  106.   void Clear(void);
  107.  
  108. };
  109.  
  110. #endif // IN_CPROTO
  111. #endif // wxb_hashh
  112.